package com.haiyi.software.app.basic;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.packet.Message;

import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.haiyi.software.app.MainApplication;
import com.haiyi.software.app.R;
import com.haiyi.software.dao.ChatDAO;
import com.haiyi.software.xmpp.event.XMPPEvent;

public abstract class FragmentBasicInformation extends FragmentBasic implements
		XMPPEvent {

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO 自动生成的方法存根
		return super.onCreateView(inflater, container, savedInstanceState);
	}

	protected MainApplication app;

	private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

	public List<Map<String, Object>> data = new ArrayList<Map<String, Object>>();

	@Override
	public synchronized void requestNetworkData() {
		// TODO 自动生成的方法存根

		new GetDataTask().execute();
	}

	private class GetDataTask extends
			AsyncTask<Void, Void, List<Map<String, Object>>> {

		@Override
		protected List<Map<String, Object>> doInBackground(Void... params) {

			ChatDAO dao = ChatDAO.getInstence();

			list.clear();
			list.addAll(dao.getInformationCount());

			return null;
		}

		@Override
		protected void onPostExecute(List<Map<String, Object>> result) {
			// TODO 自动生成的方法存根
			super.onPostExecute(result);

			data.clear();
			data.addAll(list);
			requestFinish();
		}

	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO 自动生成的方法存根
		super.onCreate(savedInstanceState);

		app = MainApplication.getInstance();

		app.addXMPPEvent(this);
	}

	@Override
	public void XMPPConnectEvent(XMPPConnection connection) {
		// TODO 自动生成的方法存根

	}

	@Override
	public void XMPPAuthenticate(XMPPConnection connection) {
		// TODO 自动生成的方法存根

	}

	@Override
	public void XMPPNotAuthenticate(XMPPConnection connection) {
		// TODO 自动生成的方法存根

	}

	@Override
	public void XMPPReceiveMessage(Message msg) {
		// TODO 自动生成的方法存根
		this.requestNetworkData();
	}
}
